﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Bussiness
{
    /// <summary>
    /// 统计量类
    /// </summary>
    public class SysParament
    {
        /// <summary>
        /// 返回参数配置结果集
        /// </summary>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public DataTable GetSysParaByMoudle(string paraMoudle)
        {
            string sql = "SELECT * FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAMODULE='"+paraMoudle+"'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回参数类型结果集
        /// </summary>
        /// <returns></returns>
        public DataTable GetSysParaType()
        {
            string sql = "SELECT DISTINCT(PARATYPE) FROM ADMINISTRATOR.T_SYS_PARA";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回参数类型结果集
        /// </summary>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public DataTable GetSysParaType(string paraMoudle)
        {
            string sql = "SELECT DISTINCT(PARATYPE) FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAMODULE='"+paraMoudle+"'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回统计量参数配置查询结果
        /// </summary>
        /// <param name="paraType">参数类型</param>
        /// <returns></returns>
        public DataTable GetUpdataSysPara(string paraType,string computeType)
        {
            string sql = "";
            if (paraType == "0")
                sql = "SELECT PARAID,PARADESC || '(' || PARAUNIT || ')',PARATYPE FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAMODULE='"+computeType+"'";
            else
                sql = "SELECT PARAID,PARADESC || '(' || PARAUNIT || ')',PARATYPE FROM ADMINISTRATOR.T_SYS_PARA WHERE PARATYPE='" + paraType + "' AND PARAMODULE='" + computeType + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回统计量参数配置查询结果
        /// </summary>
        /// <param name="paraType">参数类型</param>
        /// <returns></returns>
        public DataTable GetSysPara(string paraType)
        {
            string sql="";
            if (paraType == "0")
                sql = "SELECT * FROM ADMINISTRATOR.T_SYS_PARA ";
            else
                sql = "SELECT * FROM ADMINISTRATOR.T_SYS_PARA WHERE PARATYPE='" + paraType + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回参数配置集
        /// </summary>
        /// <param name="paraType">参数类型</param>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public DataTable GetSysPara(string paraType, string paraMoudle)
        {
            string sql = "";
            if (paraType == "0")
                sql = "SELECT * FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAMODULE='"+paraMoudle+"'";
            else
                sql = "SELECT * FROM ADMINISTRATOR.T_SYS_PARA WHERE PARATYPE='" + paraType + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回统计量参数配置描述
        /// </summary>
        /// <param name="paraID">统计量编号</param>
        /// <returns></returns>
        public string GetParaDescription(string paraID)
        {
            string paraDesc = "";
            string sql = "SELECT PARADESC FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                paraDesc = dt.Rows[0][0].ToString();
            }
            return paraDesc;
        }
        /// <summary>
        /// 返回统计量参数配置描述
        /// </summary>
        /// <param name="paraID">参数编号</param>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public string GetParaDescription(string paraID, string paraMoudle)
        {
            string paraDesc = "";
            string sql = "SELECT PARADESC FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                paraDesc = dt.Rows[0][0].ToString();
            }
            return paraDesc;
        }
        /// <summary>
        /// 返回统计量编号
        /// </summary>
        /// <param name="paraDesc">统计量描述</param>
        /// <returns></returns>
        public string GetParaID(string paraDesc)
        {
            string paraID = "";
            string sql = "SELECT PARAID FROM ADMINISTRATOR.T_SYS_PARA WHERE PARADESC='" + paraDesc + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                paraID = dt.Rows[0][0].ToString();
            }
            return paraID;
        }
        public string GetParaID(string paraDesc, string paraMoudle)
        {
            string paraID = "";
            string sql = "SELECT PARAID FROM ADMINISTRATOR.T_SYS_PARA WHERE PARADESC='" + paraDesc + "' AND PARAMODULE='"+paraMoudle+"'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                paraID = dt.Rows[0][0].ToString();
            }
            return paraID;
        }
        /// <summary>
        /// 返回参数配置单位
        /// </summary>
        /// <param name="paraID"></param>
        /// <returns></returns>
        public string GetParaUnit(string paraID)
        {
            string paraUnit = "";
            string sql = "SELECT PARAUnit FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            paraUnit = link.GetFirstValue(sql).ToString();
            return paraUnit;
        }
        /// <summary>
        /// 返回参数配置单位
        /// </summary>
        /// <param name="paraID">参数编号</param>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public string GetParaUnit(string paraID, string paraMoudle)
        {
            string paraUnit = "";
            string sql = "SELECT PARAUnit FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "' AND PARAMODULE='"+paraMoudle+"'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            paraUnit = link.GetFirstValue(sql).ToString();
            return paraUnit;
        }
        /// <summary>
        /// 返回测点名称
        /// </summary>
        /// <param name="paraID"></param>
        /// <returns></returns>
        public string GetPIPointName(string paraID)
        {
            string paraTag = "";
            string sql = "SELECT PARATAG FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            paraTag = link.GetFirstValue(sql).ToString();
            return paraTag;
        }
        /// <summary>
        /// 返回测点名称
        /// </summary>
        /// <param name="paraID">参数编号</param>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public string GetPIPointName(string paraID, string paraMoudle)
        {
            string paraTag = "";
            string sql = "SELECT PARATAG FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "' AND PARAMODULE='"+paraMoudle+"'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            paraTag = link.GetFirstValue(sql).ToString();
            return paraTag;
        }
        /// <summary>
        /// 返回参数名称与单位
        /// </summary>
        /// <param name="paraID"></param>
        /// <returns></returns>
        public string GetParaNameUnit(string paraID)
        {
            string paraNameUnit = "";
            string sql = "SELECT PARAUnit,PARADESC FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                paraNameUnit = dt.Rows[0][1].ToString() + "(" + dt.Rows[0][0].ToString() + ")";
            }
            return paraNameUnit;
        }
        /// <summary>
        /// 返回参数名称与单位
        /// </summary>
        /// <param name="paraID">参数编号</param>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public string GetParaNameUnit(string paraID,string paraMoudle)
        {
            string paraNameUnit = "";
            string sql = "SELECT PARAUnit,PARADESC FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                paraNameUnit = dt.Rows[0][1].ToString() + "(" + dt.Rows[0][0].ToString() + ")";
            }
            return paraNameUnit;
        }
        /// <summary>
        /// .返回参数类型
        /// </summary>
        /// <param name="paraID">参数编号</param>
        /// <returns></returns>
        public string GetParaState(string paraID)
        {
            string sql = "SELECT PARATYPE FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            return link.GetFirstValue(sql).ToString();
        }
        /// <summary>
        /// 返回参数类型
        /// </summary>
        /// <param name="paraID">参数编号</param>
        /// <param name="paraMoudle">参数模块</param>
        /// <returns></returns>
        public string GetParaType(string paraID, string paraMoudle)
        {
            string sql = "SELECT PARATYPE FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAID='" + paraID + "' AND PARAMODULE='"+paraMoudle+"'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            return link.GetFirstValue(sql).ToString();
        }
        /// <summary>
        /// 返回报表配置参数
        /// </summary>
        /// <param name="paraMoudle"></param>
        /// <param name="paraType"></param>
        /// <returns></returns>
        public DataTable GetReportPara(string paraMoudle, string paraType)
        {
            string sql = "SELECT PARAID,PARADESC,ParaUnit FROM ADMINISTRATOR.T_SYS_PARA WHERE PARAMODULE='" + paraMoudle + "' AND PARATYPE='" + paraType + "' ORDER BY PARASORT";
            
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            return link.ExcuteRetureTable(sql);
        }
    }
}
